﻿using System.Collections.Generic;
using BattleCity.Classes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

namespace BattleCity.GameObjects
{
    public class Tank : gBaseClass
    {
        protected float ShootSpeed;

        //Анимации танка
        protected Animation _moveUpAnimation;
        protected Animation _moveDownAnimation;
        protected Animation _moveLeftAnimation;
        protected Animation _moveRightAnimation;
        protected Animation _idleUp;
        protected Animation _idleDown;
        protected Animation _idleLeft;
        protected Animation _idleRight;
        //Анимация портала 
        protected Animation _portal;
        //Анимация взрыва
        protected Animation _destroy;

        protected SoundEffect _dieSound;

        protected Direction _dir;
        protected double _dieTime;
        protected bool _isMultiShoot, _isSuper, _isShootNow;

        public byte Lives { get; set; }

        public Tank(BattleCityGame game, ref AnimationPlayer spr, Vector2 sprPosition)
            : base(game, ref spr, sprPosition, game.SpriteRec32, 0.7f)
        {
        }
        protected virtual void LoadAnimation(Dictionary<string, Animation> animList)
        {
            _moveUpAnimation = animList["moveUp"];
            _moveDownAnimation = animList["moveDown"];
            _moveLeftAnimation = animList["moveLeft"];
            _moveRightAnimation = animList["moveRight"];
            _idleUp = animList["idleUp"];
            _idleDown = animList["idleDown"];
            _idleLeft = animList["idleLeft"];
            _idleRight = animList["idleRight"];
            _portal = animList["portal"];
            _destroy = animList["destroy"];
        }
        protected void Shoot()
        {
            if (!_isMultiShoot)
                _isShootNow = true;
            var rocket = new Rocket(Game as BattleCityGame, this, this.SprPosition, ShootSpeed, _isSuper, _dir);
            rocket.Exploded += (s, e) =>
            {
                (s as Rocket).Dispose();
                _isShootNow = false;
            };
            Game.Components.Add(rocket);
        }
        public override void Initialize()
        {
            base.Initialize();
        }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }
    }
}